﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * POP3 Greeting Response Class
 *      Represents and manages the POP3 server greeting response when a connection
 * is established.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using Adaptive.Foundation;
using Adaptive.Foundation.Network.Cnr;

namespace Adaptive.Foundation.Network.Pop3
{
    /// <summary>
    /// Represents and manages the POP3 server greeting response when a connection
    /// is established.
    /// </summary>
    public sealed class GreetingResponse : CnrResponseBase 
    {
        /*--------------------------------------------------------------------------------
         * Public Event Definitions
         *------------------------------------------------------------------------------*/
        #region Public Event Definitions
        #endregion

        /*--------------------------------------------------------------------------------
         * Private Constants Declarations
         *------------------------------------------------------------------------------*/
        #region Private Constants Declarations
        #endregion

        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations

        private PositiveResponseCode _responseCode;
        private string _customPop3GreetingText;

        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public GreetingResponse()
            : base(string.Empty)
        {
            _responseCode = new PositiveResponseCode();
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether the object is being disposed.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if ((!Disposed) && (disposing))
            {
                if (_responseCode != null)
                    _responseCode.Dispose();
            }

            _responseCode = null;
            _customPop3GreetingText = null;
            base.Dispose(disposing);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets or sets the custom text value for the initial server greeting.
        /// </summary>
        /// <value>
        /// Custom text to be sent with the response.
        /// </value>
        public string CustomGreetingText
        {
            get { return _customPop3GreetingText; }
            set { _customPop3GreetingText = value; }
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Methods / Event Methods
         *------------------------------------------------------------------------------*/
        #region Protected Methods / Event Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override CnrDataParserBase CreateParserInstance()
        {
            return new Pop3Parser();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override CnrDataRendererBase CreateRendererInstance()
        {
            return new Pop3Renderer();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="originalData"></param>
        protected override void ParseContent(string originalData)
        {
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Public Methods / Functions
        /// <summary>
        /// Clears the contents of the object instance without disposing of the instance.
        /// </summary>
        public override void Clear()
        {
            base.Clear();
            _customPop3GreetingText = string.Empty;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override string RenderResponse()
        {
            return RenderResponse(new Pop3Renderer());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="renderer"></param>
        /// <returns></returns>
        protected override string RenderResponse(CnrDataRendererBase renderer)
        {
            Pop3Renderer popRenderer = (Pop3Renderer)renderer;

            return popRenderer.RenderErrorCode(_responseCode);
            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="originalData"></param>
        protected override void ParseResponse(CnrDataParserBase parser, string originalData)
        {
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Private Event Handlers
         *------------------------------------------------------------------------------*/
        #region Private Event Handlers
        #endregion

        /*--------------------------------------------------------------------------------
         * Private Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Private Methods / Functions
        #endregion

    }
}
